<?php

namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use App\Models\Auth\UserOtp;
use Illuminate\Http\Request;

class OtpAuthController extends Controller
{
    public function otpLogin(Request $request) {
        $otpInput = $request->input('otp');

        $otp = UserOtp::where('otp', $otpInput)->first();
        logger($otpInput);
        if (empty($otp)) return response()->json(false);

        $token = $otp->user->createToken('btsc-rsms-user')->accessToken;
        $otp->delete();
        return response()->json($token);
    }
}
